/*
 * Graph.java
 *
 * Created on 31 de enero de 2007, 08:49 AM
 */

package networkFlow;

/**
 *
 * @author tavobula
 */
public class Network {
    private int Vcnt, Ecnt;
    
    
    private class Node{
        Edge e; Node next;
        
        Node(Edge x, Node t){
            e=x;
            next=t;
        }
    }
    
    private Node adj[];
    /** Creates a new instance of Graph */
    public Network(int V){
        Vcnt=V;
        Ecnt=0;
        adj=new Node[V];
    }
    
    public int getV(){return Vcnt;}
    
    public int getE(){return Ecnt;}
    
    public void insert(Edge e){
        int v=e.getV();
        int w=e.getW();
        adj[v]=new Node(e, adj[v]);
        adj[w]=new Node(e, adj[w]);
        Ecnt++;
    }
    
    public void remove(Edge e){
        int v=e.getV();
        int w=e.getW();
        adj[v]=null;
        adj[w]=null;
        Ecnt--;
    }
    
    public AdjList getAdjList(int v){
        return new AdjLinkedList(v);
    }
    
    private class AdjLinkedList implements AdjList{
        private  int v;
        private Node t;
        
        AdjLinkedList(int v){
            this.v=v;
            t=null;
        }
        
        public Edge beg(){
            t=adj[v];
            if(t!=null) return t.e;
            return null;
        }
        
         public Edge nxt(){
            if(t!=null) t=t.next;
            if(t!=null) return t.e;
            return null;
        }
        
        
        public boolean end(){
            return t==null;
        }
        
        
    }
    
    
}
